/**
 * 
 */
package com.yidin.lsc;

import java.util.List;
import com.yidin.lsc.NavigationPage.Navigation;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author cola
 * 
 */
public class NavigationAdapter extends BaseAdapter {

	private Context context;

	private List<Navigation> userInfos;

	public NavigationAdapter(Context context, List<Navigation> userInfos) {

		this.context = context;
		this.userInfos = userInfos;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.userInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.userInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;

		ViewHolder holder = null;
		if (view == null) {

			view = LayoutInflater.from(context).inflate(R.layout.list_item,
					null);

			holder = new ViewHolder();
			view.setTag(holder);
			holder.tv_catalog = (TextView) view.findViewById(R.id.tv_catalog);
			holder.tv_nick = (TextView) view.findViewById(R.id.tv_nick);
			holder.icon = (ImageView) view
					.findViewById(R.id.contactitem_avatar_iv);
			// holder.tv_mobile = (TextView) view.findViewById(R.id.tv_mobile);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (userInfos.get(position).title.equals("")) {
			holder.tv_catalog.setVisibility(View.GONE);
		} else {
			holder.tv_catalog.setVisibility(View.VISIBLE);
			if (userInfos.get(position).title.equals("优惠圈")) {
				holder.tv_catalog.setBackgroundResource(R.drawable.pyq_bg);
			} else if (userInfos.get(position).title.equals("活动圈")) {
				holder.tv_catalog.setBackgroundResource(R.drawable.hdq_bg);
			} else if (userInfos.get(position).title.equals("朋友圈")) {
				holder.tv_catalog.setBackgroundResource(R.drawable.hdq_bg2);
			}
			holder.tv_catalog.setText(userInfos.get(position).title);
			holder.tv_catalog.setTextColor(Color.WHITE);
		}
		holder.icon.setImageDrawable(context.getResources().getDrawable(
				userInfos.get(position).icon));
		holder.tv_nick.setText(userInfos.get(position).content);
		return view;
	}

	class ViewHolder {

		TextView tv_catalog;
		TextView tv_nick;
		ImageView icon;
	}
}
